
package interface_graphique;

import ClassesJava.Cour;
import ClassesJava.Matieres;
import ClassesJava.Professeur;
import ClassesJava.Salle;
import static interface_graphique.EmploieDeTemps.E;
import static interface_graphique.EmploieDeTemps.FChoise;
import java.awt.List;

import java.util.ArrayList;
import static java.util.Collections.list;

import java.util.Vector;

/**
 *
 * @author ISMAYLOULABBIHI
 */
public class TraiterZone extends javax.swing.JFrame {

    private Salle s;
    private Matieres m;
    private Professeur p;
    ArrayList<Salle> listeS = new ArrayList();
    ArrayList<Professeur> listeP = new ArrayList();
    ArrayList<Matieres> listeM = new ArrayList();
    private ArrayList  listSalle = new ArrayList();
    private boolean b=false;

    /**
     * Creates new form TraiterZone
     */
    public TraiterZone() {

        initComponents();
        setLocationRelativeTo(null);
        s = new Salle();
        m = new Matieres();
        p = new Professeur();
        afficherMatieres();
        afficherSalleByZone(E.co.getRow(),E.co.getCol());
    }

    public void afficherMatieres() {
        jComMatiere.removeAllItems();
        Vector<Matieres> res = new Vector();
        res = m.getMatieres();
        for (int i = 0; i < res.size(); i++) {
            listeM.add(res.get(i));
            jComMatiere.addItem(res.get(i).getLabel());

        }
    }

   
     public void afficherProfByZone(String matiere,int row, int col) {
        jComProf.removeAllItems();
        Vector<Professeur> res = new Vector();
        res = p.getProfByMatieresByZone(matiere, col, row);
        for (int i = 0; i < res.size(); i++) {
            listeP.add(res.get(i));
            jComProf.addItem(res.get(i).getNom() + "  " + res.get(i).getPrenom());

        }
    }
public void afficherSalleByZone(int row, int col) {
        jComSalle.removeAllItems();
        Vector<Salle> res = new Vector();
        res = s.getSalleByZone(col, row);
        for (int i = 0; i < res.size(); i++) {
            listeS.add(res.get(i));
            jComSalle.addItem(res.get(i).gettype() + ":" + res.get(i).getbloc());
           
            listSalle.add(res.get(i).getNum());
        }
        b=true;
        
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jComSalle = new javax.swing.JComboBox();
        jComProf = new javax.swing.JComboBox();
        jComMatiere = new javax.swing.JComboBox();
        Aplique = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        txtSalle = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        setUndecorated(true);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setText("Matieres");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 60, 81, 23));

        jLabel2.setText("Professeur:");
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 100, 81, 23));

        jLabel3.setText("Salle:");
        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 140, 81, 23));

        jComSalle.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComSalle.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComSalleItemStateChanged(evt);
            }
        });
        getContentPane().add(jComSalle, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 140, 193, 29));

        jComProf.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComProf.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jComProfActionPerformed(evt);
            }
        });
        getContentPane().add(jComProf, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 100, 193, 29));

        jComMatiere.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComMatiere.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComMatiereItemStateChanged(evt);
            }
        });
        getContentPane().add(jComMatiere, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 60, 193, 29));

        Aplique.setText("Apliquer");
        Aplique.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ApliqueActionPerformed(evt);
            }
        });
        getContentPane().add(Aplique, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 220, 130, -1));

        jLabel7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/quite.png"))); // NOI18N
        jLabel7.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel7.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel7MouseClicked(evt);
            }
        });
        getContentPane().add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 0, 40, -1));
        getContentPane().add(txtSalle, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 170, 190, 30));

        getAccessibleContext().setAccessibleDescription("");

        pack();
    }// </editor-fold>//GEN-END:initComponents


    private void jComProfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComProfActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jComProfActionPerformed

    private void jComMatiereItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComMatiereItemStateChanged
        if (jComMatiere.getSelectedIndex() != -1) {
            //afficherProfesseur(jComMatiere.getItemAt(jComMatiere.getSelectedIndex()).toString());
            afficherProfByZone(jComMatiere.getItemAt(jComMatiere.getSelectedIndex()).toString(),E.co.getRow(),E.co.getCol());
        }
    }//GEN-LAST:event_jComMatiereItemStateChanged

    private void ApliqueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ApliqueActionPerformed
        E.co.setIdFiliere(FChoise.getNum());
        E.co.setIdProf(listeP.get(jComProf.getSelectedIndex()).getId());
        E.co.setNumMatier(listeM.get(jComMatiere.getSelectedIndex()).getNum());
        E.co.setNumsalle(listeS.get(jComSalle.getSelectedIndex()).getNum());
          
        E.co.setDescription(jComMatiere.getSelectedItem() + " \n" + jComSalle.getSelectedItem() + "\n Prof:" + jComProf.getSelectedItem());
        E.setZone();
        E.co.updateCour(E.co);
        this.setVisible(false);
    }//GEN-LAST:event_ApliqueActionPerformed

    private void jLabel7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel7MouseClicked
        this.setVisible(false);
             
    }//GEN-LAST:event_jLabel7MouseClicked

    private void jComSalleItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComSalleItemStateChanged
       
       if(b==true){
        Salle s= new Salle();
       s = s.getSalleById((int) listSalle.get(jComSalle.getSelectedIndex()));       
        txtSalle.setText("Nembre plase:"+ s.getNbplace());
       }
       
    }//GEN-LAST:event_jComSalleItemStateChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TraiterZone.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TraiterZone.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TraiterZone.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TraiterZone.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new TraiterZone().setVisible(true);

            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Aplique;
    private javax.swing.JComboBox jComMatiere;
    private javax.swing.JComboBox jComProf;
    private javax.swing.JComboBox jComSalle;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel txtSalle;
    // End of variables declaration//GEN-END:variables

}
